import Group from "../entities/Group";
import Operator from "./Operator";
import { RC } from "../config/RC";

class CheckGroupNameExistOperator extends Operator {
    public async execute(): Promise<RC> {
        try {
            const group_name = this.args.getProperty("groupName");
            if (group_name === '' || group_name === null || group_name === undefined) {
                console.log(1);
                return RC.INVALID_ARGUMENT;
            }
            const isExist = await Group.CheckGroupNameExist(group_name);
            if (isExist) return RC.GROUPNAME_EXIST;
            else return RC.SUCCESS;
        } catch (error) {
            // 处理异常情况
            console.error('Error checking group_name existence:', error);
            return RC.INTERNAL_ERROR;
        }
    }
}

export default CheckGroupNameExistOperator;